package com.app.controller;

import com.app.model.response.RetStatus;
import com.app.model.util.ArticleFlag;
import com.app.service.ArticleService;
import com.app.service.RecommendService;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
 * Created by Lichaojie on 2017/3/15. It's a beautiful day.
 */
@RequestMapping(value = "/article")
@RestController
public class ArticleController {

    private Log log = LogFactory.getLog(ArticleController.class);

    @Autowired
    private ArticleService articleService;
    @Autowired
    private RecommendService recommendService;


    //新增，发布帖子的接口
    @RequestMapping(value = "/publish")
    public RetStatus publishArticle(@RequestBody String parameter){
        try {
            articleService.publishArticle(parameter);
            return new RetStatus().setCode(100).setMessage("成功");
        }catch (Exception e){
            return new RetStatus().setCode(200).setMessage(e.getMessage());
        }
    }

    /*@RequestMapping(value = "/publishShare")
    public RetStatus publishShare(@RequestBody String parameter) {
        try {
            articleService.publishArticle(parameter);
            return new RetStatus().setCode(100).setMessage("成功");
        }catch (Exception e){
            return new RetStatus().setCode(200).setMessage(e.getMessage());
        }
    }

    @RequestMapping(value = "/publishHelp")
    public RetStatus publishHelp(@RequestBody String parameter){
        try{
            articleService.publishArticle(parameter);
            return new RetStatus().setCode(100).setMessage("成功");
        }catch (Exception e){
            return new RetStatus().setCode(200).setMessage(e.getMessage());
        }
    }

    //新增，发布分享&金币帖
    @RequestMapping(value="/share/coin")
    public RetStatus publishShareCoin(@RequestBody String parameter){
        try{
            articleService.publishArticle(parameter);
            return new RetStatus().setCode(100).setMessage("成功");
        }catch (Exception e){
            return new RetStatus().setCode(200).setMessage(e.getMessage());
        }
    }

    //新增，发布求助&金币帖
    @RequestMapping(value = "/help/coin")
    public RetStatus publishHelpCoin(@RequestBody String parameter){
        try{
            articleService.publishArticle(parameter);
            return new RetStatus().setCode(100).setMessage("成功");
        }catch (Exception e){
            return new RetStatus().setCode(200).setMessage(e.getMessage());
        }
    }

    //新增，发布分享&置顶帖
    @RequestMapping(value = "/share/top")
    public RetStatus publishShareTop(@RequestBody String parameter){
        try{
            articleService.publishArticle(parameter);
            return new RetStatus().setCode(100).setMessage("成功");
        }catch (Exception e){
            return new RetStatus().setCode(200).setMessage(e.getMessage());
        }
    }

    //新增，发布求助&置顶帖
    @RequestMapping(value = "/help/top")
    public RetStatus publishHelpTop(@RequestBody String parameter) {
        try{
            articleService.publishArticle(parameter);
            return new RetStatus().setCode(100).setMessage("成功");
        }catch (Exception e){
            return new RetStatus().setCode(200).setMessage(e.getMessage());
        }
    }

    //新增，发布求助&悬赏帖
    @RequestMapping(value = "/help/reward")
    public RetStatus publishHelpReward(@RequestBody String parameter){
        try{
            articleService.publishArticle(parameter);
            return new RetStatus().setCode(100).setMessage("成功");
        }catch (Exception e){
            return new RetStatus().setCode(200).setMessage(e.getMessage());
        }
    }

    //新增，发布求助&置顶&悬赏帖
    @RequestMapping(value = "/help/top/reward")
    public RetStatus publishTopReward(@RequestBody String parameter) {
        try{
            articleService.publishArticle(parameter);
            return new RetStatus().setCode(100).setMessage("成功");
        }catch (Exception e){
            return new RetStatus().setCode(200).setMessage(e.getMessage());
        }
    }

    //新增，发布求助&金币&悬赏帖
    @RequestMapping(value = "/help/coin/reward")
    public RetStatus publishCoinReward(@RequestBody String parameter) throws Exception{
        try{
            articleService.publishArticle(parameter);
            return new RetStatus().setCode(100).setMessage("成功");
        }catch (Exception e){
            return new RetStatus().setCode(200).setMessage(e.getMessage());
        }
    }*/

    //新增，精选帖
    @RequestMapping(value = "/recommend")
    public RetStatus getRecommend(@RequestBody String parameter){
        return articleService.getRecommend(parameter);
    }

    //新增，置顶帖
    @RequestMapping(value = "/tops")
    public RetStatus getTops(@RequestBody String parameter){
        return articleService.getTops(parameter);
    }



    @RequestMapping(value = "/getArticleDetails",method = RequestMethod.POST)
    public RetStatus getArticleDetails(@RequestBody String parameter){
        return articleService.getArticleDetails(parameter);
    }

    @RequestMapping(value = "/doSearch")
    public RetStatus doSearch(@RequestBody String parameter){
        return articleService.doSearch(parameter);
    }

    @RequestMapping(value = "/getMyShare/Update")
    public RetStatus getMyShareUpdate(@RequestBody String parameter){
        return articleService.getUpdate(parameter, ArticleFlag.SHARE);
    }

    @RequestMapping(value = "/getMyShare/LoadMore")
    public RetStatus getMyShareLoadMore(@RequestBody String parameter){
        return articleService.getLoadMore(parameter, ArticleFlag.SHARE);
    }

    @RequestMapping(value = "/getMyHelp/Update")
    public RetStatus getMyHelpUpdate(@RequestBody String parameter){
        return articleService.getUpdate(parameter, ArticleFlag.HELP);
    }

    @RequestMapping(value = "/getMyHelp/LoadMore")
    public RetStatus getMyHelpLoadMore(@RequestBody String parameter){
        return articleService.getLoadMore(parameter, ArticleFlag.HELP);
    }


    @RequestMapping(value = "/doScanRecord")
    public RetStatus doScanRecord(@RequestBody String parameter){
        return articleService.doScanRecord(parameter);
    }


    //修改，增加帖子类型说明
    @RequestMapping(value = "/getHelpRecommend/Update")
    public RetStatus getHelpRecommendUpdate(@RequestBody String parameter){
        return articleService.getUpdateWithoutUserId(parameter, ArticleFlag.HELP);
    }

    //修改，增加帖子类型说明
    @RequestMapping(value = "/getHelpRecommend/LoadMore")
    public RetStatus getHelpRecommendLoadMore(@RequestBody String parameter){
        return articleService.getLoadMoreWithoutUserId(parameter, ArticleFlag.HELP);
    }

    //修改，增加帖子类型说明
    @RequestMapping(value = "/getShareRecommend/LoadMore")
    public RetStatus getShareRecommendLoadMore(@RequestBody String parameter){
        //return articleService.getShareRecommendLoadMore(parameter);
        return recommendService.getShareRecommendLoadMore(parameter, ArticleFlag.SHARE);
    }

    //修改，增加帖子类型说明
    @RequestMapping(value = "/getShareRecommend/Update")
    public RetStatus getShareRecommendUpdate(@RequestBody String parameter){
        //return articleService.getShareRecommendUpdate(parameter);
        return recommendService.getShareRecommendUpdate(parameter, ArticleFlag.SHARE);
    }

    @RequestMapping(value = "/doDelete")
    public RetStatus doDelete(@RequestBody String parameter){
        return articleService.doDelete(parameter);
    }

    @RequestMapping(value = "/getApprovalAndCommentsNumber")
    public RetStatus getApprovalAndCommentsNumber(@RequestBody String parameter){
        return articleService.getApprovalAndCommentsNumber(parameter);
    }

}
